<template>
	<view>
		<view class="content">
			<view>
				<uni-section title="所有报销单" type="line" />
				<text class="tips" v-if="listData.length <= 0">无报销单！</text>
				<uni-list style="width:95%">
					<uni-collapse>
						<uni-collapse-item 
						:open="true"
						:title="'团队： ' + v.team.name" 
						:show-animation="true" 
						style="margin-left: 20rpx;"
						v-for="(v,key) in listData" :key="key">
							<uni-list-chat v-for="item in v.reimbursements"
							:key="item.reimbursement.id"
							:avatar="item.employee.avatar"
							:title="item.employee.realName == null || item.employee.realName == '' ? item.employee.nickName : item.employee.realName" 
							:note="item.reimbursement.title + '  ' + (item.reimbursement.auditLevel == 0 ? '待审核' : item.reimbursement.auditLevel < v.team.auditLevel ? '审核中' : item.reimbursement.auditReimStatus == 'DONE' ? '已报销' : '待报销')" 
							:time="item.reimbursement.createTime" 
							:clickable="true" 
							:badge-text="(item.reimbursement.auditSubmit == 'NO' && item.employee.userId == user.userId) ? '可编辑' : item.reimbursement.cost + '元'" 
							@click="goDetail(item)" />
						</uni-collapse-item>
					</uni-collapse>
				</uni-list>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listData: [],
				user: {},
			}
		},
		onLoad(){
			this.user = this.$dry.get("user");
		},
		onShow(){
			this.getReimbursementList();
			
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		      console.log(res.target)
		    }
		    return {
		      title: '大家都在用这款小工具管理项目，快来试试吧！！！',
		      path: '/pages/index/index'
		    }
		},
		methods: {
			getReimbursementList(){
				var token = this.$dry.getToken();
				if(token){
				    var data = this.$request.run("getAllReimByOwner",token);
				    uni.request({
				    	url: data.url,
				    	method: data.method,
				    	header: data.header,
				    	data: {},
				    	success: data => {
							this.listData = data.data;
						}
					})
				}
			},
			goDetail(item){
				this.$dry.set("reim_data",item);
				if(item.reimbursement.auditSubmit == 'NO' && item.employee.userId == this.user.userId){
					uni.navigateTo({
						url: '../new/reimbursement-new-edit'
					})
				} else{
					uni.navigateTo({
						url: 'reim-detail'
					})
				}
			}
		}
	}
</script>

<style>
.tips{
	padding:10rpx 20rpx;
	text-align: left;
	font-size: 24rpx;
	color: #0077AA;
}
</style>
